#ifndef __DEF_APPCONSTANT_H__
#define __DEF_APPCONSTANT_H__

#define APPTITLE _T("KakeiboMeister")
#define BINTITLE _T("kakeibom")
#define CREATOR _T("ISHII Eiju")
#define APPVER _T("0.5.0")
#define APPSYSICONS _T("kaksysicon.png")
#define EMAIL _T("lumidina@gmail.com")

#define CREATE_TBL_BUDGET \
	_T("create table db_budgets (bg_date varchar(20), bg_id integer, bg_io integer, bg_handle integer, bg_expense integer, bg_items integer, bg_income integer, bg_expenditure integer, bg_memo varchar(50), bg_extra varchar(10));")

#define CREATE_TBL_TOTAL \
	_T("create table db_total (tot_date varchar(20), tot_handle integer, tot_income integer, tot_expenditure integer, tot_remainder integer);")

#define CREATE_TBL_EXPENSE \
	_T("create table db_expense (ex_id integer primary key, ex_io integer, ex_image integer, ex_name varchar(25), ex_account varchar(1));")

#define CREATE_TBL_ITEMS \
	_T("create table db_items (it_id integer, it_image integer, it_expense integer, it_name varchar(25));")

#define CREATE_TBL_ACCOUNT \
	_T("create table db_account (ac_id integer primary key, ac_name varchar(25), ac_initial integer);")

#define CREATE_TBL_COUNTER \
	_T("create table db_counter (ct_budget integer, ct_total integer, ct_expense integer, ct_items integer, ct_account integer);")
	
#define CREATE_VIEW_BUDGET \
	wxString::Format(_T("%s %s %s %s ;"), \
		_T("create view vw_budgets as "), \
		_T("select a.bg_date vm_date, a.bg_io vm_io, b.ac_name vm_account, c.ex_name vm_expense, d.it_name vm_items, a.bg_income vm_income, a.bg_expenditure vm_expenditure, a.bg_memo vm_memo"), \
		_T("from db_budgets a, db_accounts b, db_expense c, db_items d "), \
		_T("where a.bg_handle = b.ac_id and a.bg_io = c.ex_io and a.bg_expense = c.ex_id and a.bg_expense = d.it_expense and a.bg_items = d.it_id;"))

#define CREATE_TBL_CONFIG \
	_T("create table db_config (cf_name varchar(20), cf_value varchar(20));")

#define CREATE_TBL_PERIOD \
	_T("create table db_period (pr_id integer primary key, pr_date varchar(20), pr_periodtype integer, pr_day integer, pr_holiday integer, pr_inputval varchar(1), pr_inputmemo varchar(1), pr_io integer, pr_handle integer, pr_expense integer, pr_items integer, pr_income integer, pr_expenditure integer, pr_memo varchar(50));")

#define CREATE_TBL_RESERVED \
	_T("create table db_reserved (rs_id integer primary key, rs_type integer, rs_handle integer, rs_start varchar(20), rs_end varchar(20), rs_budget integer);")

#define Msgbox(MES,OBJ) (wxMessageBox(MES,APPTITLE,wxOK,OBJ))

#define IntToStr(VAL) (wxString::Format(_T("%d"),VAL))

#define StrF wxString::Format

#define DATEFORM _T("%Y/%m/%d")

typedef int mon_int;

#define P_SHARE 0
#define P_DOC 1
#define P_LOCALE 2
#define P_APPNAME 3
#define P_ICON 4

//long define
const wxString WXSQL_FOR_DATERANGE = StrF(_T("%s %s %s %s %s %s"),
		_T("select ex_name, it_name, sum(bg_income) + sum(bg_expenditure), ex_io "),
		_T("from (select ex_id, ex_io, ex_name, ifnull(it_id,-1) it_id, it_name "),
		_T(" from db_expense left join db_items on ex_id = it_expense) "),
		_T("left join (select * from db_budgets where bg_date between '%s' and '%s' and bg_handle = %d) "),
		_T("on (bg_expense = ex_id and bg_items = it_id) "),
		_T("group by ex_id, it_id order by ex_io;")
		);

const wxString WXSQL_FOR_INITIALREMAINDER  = StrF(_T("%s %s %s"),
		_T("select ifnull(sum(tot_remainder-tot_income+tot_expenditure),0) "),
		_T("from db_total "),
		_T("where tot_date = (select min(tot_date) from db_total where tot_handle = %d);")
		);

const wxString WXSQL_FOR_EXPENSEONLY = StrF(_T("%s %s %s %s"),
		_T("select ex_name, ifnull(income,0), ifnull(expenditure,0) from db_expense left join "),
		_T("(select bg_date, sum(bg_income) income, sum(bg_expenditure) expenditure,bg_expense "),
		_T("from db_budgets where bg_date between '%s' and '%s' and bg_handle = %d"),
		_T("group by bg_expense) on ex_id = bg_expense order by ex_io, ex_id;")
		);

const wxString WXSQL_GET_EXPENSE_AND_ITEM = 
	_T("select ex_name, it_name from db_expense, db_items where ex_id = %d and it_id = %d and ex_id = it_expense;");

const wxString WXSQL_GET_PERIOD_CNT_IF_TIMING =
	_T("select count(*) from db_period where pr_periodtype = %d;");

const wxString WXSQL_GET_FAVORATE_ONLY = 
	_T("select * from db_period where pr_periodtype = %d;");

#define DetailCreateColumn(LIST) \
	itemcol.SetText(_("Date")); \
	LIST->InsertColumn(0,itemcol); \
	LIST->SetColumnWidth(0, 90); \
	itemcol.SetText(_("Expense")); \
	LIST->InsertColumn(1,itemcol); \
	LIST->SetColumnWidth(1, 100); \
	itemcol.SetText(_("Items")); \
	LIST->InsertColumn(2,itemcol); \
	LIST->SetColumnWidth(2, 100); \
	itemcol.SetText(_("Handling")); \
	LIST->InsertColumn(3,itemcol); \
	LIST->SetColumnWidth(3, 70); \
	itemcol.SetText(_("Income")); \
	itemcol.SetAlign(wxLIST_FORMAT_RIGHT); \
	LIST->InsertColumn(4,itemcol); \
	LIST->SetColumnWidth(4, 90); \
	itemcol.SetText(_("Expenditure")); \
	itemcol.SetAlign(wxLIST_FORMAT_RIGHT); \
	LIST->InsertColumn(5,itemcol); \
	LIST->SetColumnWidth(5, 90); \
	itemcol.SetText(_("Memo")); \
	itemcol.SetAlign(wxLIST_FORMAT_LEFT); \
	LIST->InsertColumn(6,itemcol); \
	LIST->SetColumnWidth(6, 200);

//void WriteLog(const wxString &mes) { wxLogMessage(mes.c_str()); }
//void WriteLog(const wxChar *mes) { wxLogMessage(mes); }

#endif

